import { RequestHandler } from 'express';
import { req_info_music_audio_upload } from '../Classes/cla_req_info_upload_music_audio';
import { spacename_audio } from '../DataDefine/sourceData';
import { log_sign_cur_user_audio_upload } from '../Func/Log_info';
import { cla_res_send_music_audio_upload } from '../Classes/cla_res_send_music_audio_upload';
import { set_file_music_audio_upload } from '../Func/Set_file';
import { get_cur_db_count_for_id } from '../../../../../../../../../Func/get_mdb_new_id';
import { get_global_db_audio } from '../../../../../../../../../Func/get_global_db';
import { sign_identity_global_audio } from '../global/Func/Log_info';
/**
 * 上传 音频 文件
 */
export const upload_music_audio: RequestHandler = async (req, res) => {
  let req_info = new req_info_music_audio_upload(req);

  /**
   * audio 音频 文件
   */
  let file = req.file;

  if (!file) {
    res.send({ describe: '未上传 文件' });
    return;
  }

  /**
   * 请求获取 global_audio 总数据量
   */
  let squeue_num = await get_cur_db_count_for_id(get_global_db_audio());

  /**
   * 设定 当前 文件 id
   */
  req_info.id = `${spacename_audio}_${squeue_num}`;

  /**
   * 全局 audio 身份 登记
   */
  sign_identity_global_audio(req_info);

  /**
   * 用户 操作 日志
   */
  log_sign_cur_user_audio_upload(req_info);

  /**
   * 存 文件 一式两份
   */
  set_file_music_audio_upload(req_info, file);

  /**
   * 回遣 消息
   */
  let res_send = new cla_res_send_music_audio_upload();

  res.send(res_send);
};
